#include <myheader_c_plus.h>
#include <log4cpp/OstreamAppender.hh>
#include <log4cpp/FileAppender.hh>
#include <log4cpp/RollingFileAppender.hh>
#include <log4cpp/PatternLayout.hh>
#include <log4cpp/Category.hh>  
using namespace std;
using namespace log4cpp;
void test1(){
    //设置日志布局
    PatternLayout *ptn1 = new PatternLayout();
    ptn1->setConversionPattern("%d %c [%p] %m%n");
    PatternLayout *ptn2 = new PatternLayout();
    ptn2->setConversionPattern("%d %c [%p] %m%n");
    PatternLayout *ptn3 = new PatternLayout();
    ptn3->setConversionPattern("%d %c [%p] %m%n");

    //绑定输出器
    OstreamAppender *os = new OstreamAppender("console",&cout);
    os->setLayout(ptn1);

    FileAppender *file = new FileAppender("file","system.log");
    file->setLayout(ptn2);

    //回卷日志
    RollingFileAppender *roll = new RollingFileAppender("Rolling","system_roll.log", 5*1024, 4);
    roll->setLayout(ptn3);

    //创建日志记录器sale模块
    Category & saleDepart = Category::getInstance("saleDepart");
    //设置优先级
    saleDepart.setPriority(Priority::ERROR);
    //设置输出器
    saleDepart.addAppender(os);
    saleDepart.addAppender(file);
    saleDepart.addAppender(roll);


    //记录日志
    for(int i = 0; i < 1000; i++){
        saleDepart.emerg("this is an emergency error");
        saleDepart.error("this is an error error");
        saleDepart.debug("this is a debug error");
        saleDepart.fatal("this isa fatal error");
        saleDepart.emerg("this is an emergency error");
        saleDepart.emerg("this is an emergency error");
        saleDepart.emerg("this is an emergency error");
        
    }
    


}

int main(int argc, char *argv[])
{
    test1();
    return 0;
}

